// pages/dailydelivery/dailydelivery.js
var utils = require('../../../utils/util.js');
Page({
  data: {

  },
  onLoad: function(options) {
    var that = this;
    that.system();
  },
  //基本数据
  system: function(e) {
    var that = this;
    utils.http("/api/v1/common/system", {}, function(res) {
      that.setData({
        info: res.datas
      })
    })
  },
  //进入详情
  dailyDetailsTap: function(e) {
    wx.navigateTo({
      url: '../dailydelivery/dailyDetails/dailyDetails',
    })
  },
  formSubmit: function(e) {
    var that = this;
    var name = e.detail.value.name;
    var mobile = e.detail.value.mobile;
    var address = e.detail.value.address;
    if (!that.verify(e.detail.value)) return false;
    utils.http("/api/v1/common/jinbei", {
      name: name,
      mobile: mobile,
      address: address
    }, function(res) {
      if (res.state == 1) {
        wx.showToast({
          title: '您已提交成功，请等待联系~',
          icon: "none"
        })
      }
    })
  },
  verify: function(value) {
    var msg = '';
    if (!value.name) {
      msg = '姓名不能为空';
    } else if (!value.mobile) {
      msg = '电话不能为空';
    } else if (!(/^1(3|4|5|7|8)\d{9}$/.test(value.mobile))) {
      msg = '电话格式错误';
    } else if (!value.address) {
      msg = '详细地址不能为空';
    }
    if (msg) {
      wx.showToast({
        title: msg,
          image: 'https://xinong.qidian2018.com/smimgs/error.png',
      })
      return false;
    } else {
      return true;
    }
  },
})